package com.ckzp.jfinal.interceptor;

import com.ckzp.core.ConfigUtil;
import com.ckzp.core.json.JsonResult;
import com.ckzp.jfinal.base.csrf.TokenService;
import com.ckzp.jfinal.system.cache.SysConfigCache;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

/**
 * Created by 51594 on 2022/10/13.
 */
public class ReadonlyInterceptor implements Interceptor {

    /**
     * READONLY
     * 在web.properties中定义
     */
    public static boolean READONLY = ConfigUtil.READONLY();

    /**
     * @param inv
     */
    public void intercept(Invocation inv) {
        String methName = inv.getMethod().getName();
        boolean v = false;
        //判断哪些需要判断
        if (methName.startsWith("Modify") && methName.endsWith("Api")) {
            v = true;
        } else if (methName.startsWith("Del") && methName.endsWith("Api")) {
            v = true;
        } else if (methName.startsWith("Set") && methName.endsWith("Api")) {
            v = true;
        } else if (methName.startsWith("Dr") && methName.endsWith("Api")) {
            v = true;
        }
        if (v) {
            inv.getController().renderJson(JsonResult.n().setCode(93).setMsg("演示模式禁止操作"));
        } else {
            inv.invoke();
        }
    }
}
